package com.jerkin.trace;

import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @version V1.0
 * @ClassName: ExcutorTest
 * @Description:
 * @author: huhongzhi
 * @date: 2020/7/27 18:34
 */
public class ExcutorTest {
    
    public static void main(String[] args) throws ExecutionException, InterruptedException {
//        ExecutorService executorService = Executors.newFixedThreadPool(2);
//        for (int i = 0; i < 10; i++) {
//            executorService.submit(new Runnable() {
//                @Override
//                public void run() {
//                    System.out.println("当前线程:" + Thread.currentThread().getName()
//                            + "当前的uuid"+ThreadAtmoic.getTrace());
//                }
//            });
//        }
        List<Integer> list =  Arrays.asList(10,20,30);
        //通过reduce方法得到一个Optional类
        int a =  list.stream().reduce(Integer::sum).orElse(get("a"));
        int b =  list.stream().reduce(Integer::sum).orElseGet(() -> get("b"));
        System.out.println("a  "+a);
        System.out.println("b  "+b);

    }

    public static int get(String name){
        System.out.println(name+"执行了方法");
        return 1;
    }
}
